import { defineStore } from "pinia";
import ID from "../enum";
import {
  useSetRefreshTokenStorage,
  useSetTokenStorage,
  useSetUserStorage,
  useGetUserStorage,
  useGetTokenStorage,
  useGetRefreshTokenStorage,
} from "../../hooks/useStorage";
import { reactive } from "vue";
export const useUserStore = defineStore(ID.USER, {
  state: () => {
    return {
      token: useGetTokenStorage(),
      refreshToken: useGetRefreshTokenStorage(),
      userInfo: useGetUserStorage(),
    };
  },
  // 支持同步,异步
  actions: {
    setToken(e, refreshToken) {
      this.token = e;
      this.refreshToken = refreshToken;
      useSetTokenStorage(e);
      useSetRefreshTokenStorage(refreshToken);
    },
    setUserInfo(e) {
      console.log("Store setUserInfo", e);
      useSetUserStorage(e);
      this.userInfo = useGetUserStorage();
    },
    setUserInfoDemo(e) {
      this.userInfo = e;
    },
  },
});
